/*********************************************************************************
**																				**
**																				**
**					Appendix            			                            **
**																				**
**																				**
**		Description: Replication Code for the Appendix of Stakeholder 			**
** Participation in Policymaking: Evidence from Medicare Fee Schedule Revisions **
**		Last Modified: September 11, 2019                                        **
*********************************************************************************/


/*** Notes on the Code

*** All outreg commands are commented out
*** All margins commands are also commented out as they take forever to run

*** Table A6 is commented out because the firth logit takes hours to converge

*** Order is Table A2, Table A3, Figure A1, Table A6, Table A7, Table A8, Table A4, Table A5, Table A9, and Table A11
*** All Tables are introduced by a header

*** The code for Figure A1 depends on Table A2
*** The campaign contribution regressions in Tables A4 and A5 get rid of data used in A2, A3, A6, and A7 so are afterwards
*** The code for Table A7 and A8 change the stakes variable so it is necessary to reload the data and rerun the preamble above the
code so it executes properly
*** Table A9 aggregates the data 
*** The preamble is also before table A11 because of the aggregation in A9
*/

********************************************************************************************************************************************
***																																		 ***
***																																		 ***
*** 			Appendix Table A2: Summary Statistics 																					 ***
***																																		 ***
***																																		 ***
********************************************************************************************************************************************

clear

set more off

use "Appendix.dta"

/******1. Show that autocorrelation in ln_total_allowed_sq is very high, which is why we
omit from the regression******/
sort npi year
qui by npi: gen ln_total_allowed_sq_l1 = ln_total_allowed_sq[_n-1]
corr ln_total_allowed_sq ln_total_allowed_sq_l1

/******2. Code additional covariates ******/
gen ln_delta_all_neg = ln_delta_all*(ln_delta_all<0)
gen ln_delta_all_pos = ln_delta_all*(ln_delta_all>=0)
gen ln_delta_sign_dummy = ln_delta_all >=0
gen ln_medscape_salary_geo = ln(medscape_salary_geo)
gen ln_medscape_salary = ln(medscape_salary)
gen abs_ln_delta_all = abs(ln_delta_all)
egen provideryear = group(provider_type year)
gen stakes = 0
replace stakes = log10(total_fees_sq*pct_change_all) if pct_change_all >0
replace stakes = -log10(-total_fees_sq*pct_change_all) if pct_change_all <0
gen positive_stakes = 0
gen negative_stakes = 0
replace positive_stakes = log10(total_fees_sq*pct_change_all) if pct_change_all >0
replace negative_stakes = log10(-total_fees_sq*pct_change_all) if pct_change_all <0
gen stake_dummy = pct_change_all > 0

/*Discretize Republican/Democrat/Moderate*/
gen donates_money_democrat = pct_to_republican < 1/3 & pct_to_republican !=.
gen donates_money_republican = pct_to_republican >2/3 & pct_to_republican !=.
gen donates_money_moderate = (pct_to_republican !=.)*(1-donates_money_democrat)*(1-donates_money_republican)


/*Label variables so that when they export to latex the names are correct*/
label var positive_stakes "Gains (logged)"
label var negative_stakes "Losses (logged)"
label var stake_dummy "Any gain"
label var ln_total_allowed_sq "Allowed charges (logged)"
label var hhi "Procedure concentration"
label var ln_medscape_salary_geo "Salary (logged)"
label var donates_money_dem "Any donations/Democrat"
label var donates_money_rep "Any donations/Republican"
label var donates_money_mod "Any donations/Split"
label var pgr "Percent of contributions to Republican candidates"

estpost sum positive_stakes negative_stakes stake_dummy ln_total_allowed_sq hhi ln_medscape_salary_geo donates_money_dem donates_money_rep donates_money_mod pgr

*esttab using "Output/summary_stats.tex", cells((mean(fmt(%9.3f)) count(fmt(%10.0gc)) sd(fmt(%9.3f)) min(fmt(%9.3f)) max(fmt(%9.3f)))) label nomtitle nonumber replace

********************************************************************************************************************************************
***																																		 ***
***																																		 ***
*** Appendix Table A3: Estimating the Likelihood of Notice and Comment Participation: Logit and Conditional Fixed Effect Logit Estimates ***
***																																		 ***
***																																		 ***
********************************************************************************************************************************************

*Create empty matrices so we can save positive and negative stakes from each regression
matrix negative_stakes = J(5,3,.)
matrix positive_stakes = J(5,3,.)

*Create loacal variables to simplify the regression calls.  Run these with the regressions.
local apolitical_indvars = "positive_stakes negative_stakes stake_dummy ln_total_allowed_sq hhi ln_medscape_salary_geo" 
local political_indvars = "positive_stakes negative_stakes stake_dummy ln_total_allowed_sq hhi ln_medscape_salary_geo donates_money_dem donates_money_rep donates_money_mod" 
local yeardummies = "y_1 y_2 y_3"

/*Multivariate logit models and Margin calculations */
/*Column (1) Specification*/
logit anycomment `apolitical_indvars' `yeardummies', robust cluster(provideryear) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)
**outreg2 using "Output/regression1.tex", dec(3) alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label replace

*** Calculate Marginal Effects.  Same structure for all the columns in this table
centile negative_stakes if stakes<0
local median = r(c_1)
matrix negative_stakes[1,1] = exp(b[1,2]*`median')
matrix negative_stakes[1,2] = exp((b[1,2]+sqrt(V[2,2])*invnorm(0.025))*`median')
matrix negative_stakes[1,3] = exp((b[1,2]-sqrt(V[2,2])*invnorm(0.025))*`median')
*margins, at(negative_stakes =(0 `median') stake_dummy=(0) positive_stakes =(0))
centile positive_stakes if stakes>0
local median  = r(c_1)
matrix positive_stakes[1,1] = exp(b[1,1]*`median')
matrix positive_stakes[1,2] = exp((b[1,1]+sqrt(V[1,1])*invnorm(0.025))*`median')
matrix positive_stakes[1,3] = exp((b[1,1]-sqrt(V[1,1])*invnorm(0.025))*`median')
*margins, at(positive_stakes =(0 `median') stake_dummy=(1) negative_stakes =(0))


/*Column (2) Specification: same with political controls*/
logit anycomment `political_indvars' `yeardummies', robust cluster(provideryear) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)
**outreg2 using "Output/regression1.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`political_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append
centile negative_stakes if stakes<0
local median = r(c_1)
matrix negative_stakes[2,1] = exp(b[1,2]*`median')
matrix negative_stakes[2,2] = exp((b[1,2]+sqrt(V[2,2])*invnorm(0.025))*`median')
matrix negative_stakes[2,3] = exp((b[1,2]-sqrt(V[2,2])*invnorm(0.025))*`median')
*margins, at(negative_stakes =(0 `median') stake_dummy=(0) positive_stakes =(0))
centile positive_stakes if stakes>0
local median  = r(c_1)
matrix positive_stakes[2,1] = exp(b[1,1]*`median')
matrix positive_stakes[2,2] = exp((b[1,1]+sqrt(V[1,1])*invnorm(0.025))*`median')
matrix positive_stakes[2,3] = exp((b[1,1]-sqrt(V[1,1])*invnorm(0.025))*`median')
*margins, at(positive_stakes =(0 `median') stake_dummy=(1) negative_stakes =(0))

/*Column (3) Specification -- controls for provider-year fixed effects*/
logit anycomment `apolitical_indvars' `yeardummies' year##groupid, robust cluster(provideryear) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)
**outreg2 using "Output/regression1.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append
centile negative_stakes if stakes<0
local median = r(c_1)
matrix negative_stakes[3,1] = exp(b[1,2]*`median')
matrix negative_stakes[3,2] = exp((b[1,2]+sqrt(V[2,2])*invnorm(0.025))*`median')
matrix negative_stakes[3,3] = exp((b[1,2]-sqrt(V[2,2])*invnorm(0.025))*`median')
*margins, at(negative_stakes =(0 `median') stake_dummy=(0) positive_stakes =(0))
centile positive_stakes if stakes>0
local median  = r(c_1)
matrix positive_stakes[3,1] = exp(b[1,1]*`median')
matrix positive_stakes[3,2] = exp((b[1,1]+sqrt(V[1,1])*invnorm(0.025))*`median')
matrix positive_stakes[3,3] = exp((b[1,1]-sqrt(V[1,1])*invnorm(0.025))*`median')
*margins, at(positive_stakes =(0 `median') stake_dummy=(1) negative_stakes =(0))

/*Column (4) Specification -- controls for provider-year fixed effects, political controls*/
logit anycomment `political_indvars' `yeardummies' year##groupid, robust cluster(provideryear) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)
**outreg2 using "Output/regression1.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`political_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append
centile negative_stakes if stakes<0
local median = r(c_1)
matrix negative_stakes[4,1] = exp(b[1,2]*`median')
matrix negative_stakes[4,2] = exp((b[1,2]+sqrt(V[2,2])*invnorm(0.025))*`median')
matrix negative_stakes[4,3] = exp((b[1,2]-sqrt(V[2,2])*invnorm(0.025))*`median')
*margins, at(negative_stakes =(0 `median') stake_dummy=(0) positive_stakes =(0))
centile positive_stakes if stakes>0
local median  = r(c_1)
matrix positive_stakes[4,1] = exp(b[1,1]*`median')
matrix positive_stakes[4,2] = exp((b[1,1]+sqrt(V[1,1])*invnorm(0.025))*`median')
matrix positive_stakes[4,3] = exp((b[1,1]-sqrt(V[1,1])*invnorm(0.025))*`median')
*margins, at(positive_stakes =(0 `median') stake_dummy=(1) negative_stakes =(0))

/*Column (5) Specification -- Conditional Fixed Effect Logit (Dem and GOP are time-invariant, so not estimated)*/
xtlogit anycomment `apolitical_indvars' `yeardummies', fe i(npi)
matrix b = e(b)
matrix V = e(V)
gen xt_touse = e(sample)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)
**outreg2 using "Output/regression1.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append
centile negative_stakes if stakes<0
local median = r(c_1)
matrix negative_stakes[5,1] = exp(b[1,2]*`median')
matrix negative_stakes[5,2] = exp((b[1,2]+sqrt(V[2,2])*invnorm(0.025))*`median')
matrix negative_stakes[5,3] = exp((b[1,2]-sqrt(V[2,2])*invnorm(0.025))*`median')
*margins, at(negative_stakes =(0 `median') stake_dummy=(0) positive_stakes =(0))
centile positive_stakes if stakes>0
local median  = r(c_1)
matrix positive_stakes[5,1] = exp(b[1,1]*`median')
matrix positive_stakes[5,2] = exp((b[1,1]+sqrt(V[1,1])*invnorm(0.025))*`median')
matrix positive_stakes[5,3] = exp((b[1,1]-sqrt(V[1,1])*invnorm(0.025))*`median')
*margins, at(positive_stakes =(0 `median') stake_dummy=(1) negative_stakes =(0))

********************************************************************************************************************************************
***																																		 ***
***																																		 ***
*** Figure A1: Odds Ratios for the Logit and Conditional Logit Estimating the Likelihood of Notice and Comment Participation			 ***
***																																		 ***
***																																		 ***
********************************************************************************************************************************************

svmat positive_stakes
gen height = 6-_n in 1/5
twoway (rspike positive_stakes2 positive_stakes3 height, horizontal) (scatter height positive_stakes1), scheme(plotplain) ///
legend(off) ylabel(5 "No Fixed Effects" 4 "No Fixed Effects,   " 3.8 "Political covariates" 3 "Year x Specialty Effects" ///
2 "Year x Specialty Effects," 1.8 "Political Covariates" 1 "Conditional Fixed Effects", nogrid) ///
xtitle("Odds Ratio") ytitle("") title("Positive Stakes") name(g1, replace) xline(1)

svmat negative_stakes
twoway (rspike negative_stakes2 negative_stakes3 height, horizontal) (scatter height negative_stakes1), scheme(plotplain) ///
legend(off) ylabel(5 "No Fixed Effects" 4 "No Fixed Effects,   " 3.8 "Political covariates" 3 "Year x Specialty Effects" ///
2 "Year x Specialty Effects," 1.8 "Political Covariates" 1 "Conditional Fixed Effects", nogrid) ///
xtitle("Odds Ratio") ytitle("") title("Negative Stakes") name(g2, replace) xline(0)

gr combine g2 g1
matrix list positive_stakes
matrix list negative_stakes


********************************************************************************************************************************************
***																																		 ***
***																																		 ***
*** Appendix Table A6: Estimating the Likelihood of Notice and Comment Participation with Probit, Firth Logit, and Linear Probability Models***
***																																		 ***
***																																		 ***
********************************************************************************************************************************************

asdfasdfasdf
*** CAUTION *** CAUTION *** THIS SECTION OF CODE CAN TAKE A LONG TIME TO CONVERGE (>4 Hours) ***

local apolitical_indvars = "positive_stakes negative_stakes stake_dummy ln_total_allowed_sq hhi ln_medscape_salary_geo" 
local political_indvars = "positive_stakes negative_stakes stake_dummy ln_total_allowed_sq hhi ln_medscape_salary_geo donates_money_dem donates_money_rep donates_money_mod" 
local yeardummies = "y_1 y_2 y_3"

/*Robustness to alternative specifications -- probit LPM, and penalized likelihood */
probit anycomment `apolitical_indvars' `yeardummies', robust cluster(provideryear)
**outreg2 using "Output/robust_appendix.tex", dec(3) alpha(0.001, 0.01, 0.05) keep (`apolitical_indvars') label replace
reg anycomment `apolitical_indvars' `yeardummies', robust cluster(provideryear)
**outreg2 using "Output/robust_appendix.tex", dec(3) alpha(0.001, 0.01, 0.05) keep (`apolitical_indvars') label append
firthlogit anycomment `apolitical_indvars' `yeardummies'
**outreg2 using "Output/robust_appendix.tex", dec(3) alpha(0.001, 0.01, 0.05) keep (`apolitical_indvars') label append
probit anycomment `apolitical_indvars' `yeardummies' year##groupid, robust cluster(provideryear)
**outreg2 using "Output/robust_appendix.tex", dec(3) alpha(0.001, 0.01, 0.05) keep (`apolitical_indvars') label append
reg anycomment `apolitical_indvars' `yeardummies' year##groupid, robust cluster(provideryear)
**outreg2 using "Output/robust_appendix.tex", dec(3) alpha(0.001, 0.01, 0.05) keep (`apolitical_indvars') label append
**#firthlogit anycomment `apolitical_indvars' `yeardummies' year##groupid
**outreg2 using "Output/robust_appendix.tex", dec(3) alpha(0.001, 0.01, 0.05) keep (`apolitical_indvars') label append
xtreg anycomment `apolitical_indvars' `yeardummies' year##groupid, robust cluster(provideryear), fe i(npi)
**outreg2 using "Output/robust_appendix.tex", dec(3) alpha(0.001, 0.01, 0.05) keep (`apolitical_indvars') label append


********************************************************************************************************************************************
***																																		 ***
***																																		 ***
*** Appendix Table A7: Estimating the Likelihood of Notice and Comment Participation: Logit and Conditional Fixed Effect Logit Estimates ***
***		with Unlogged Gains and Losses (Re-estimation of Table A3 with unlogged Gains and Losses)						    		     ***
***																																		 ***
***																																		 ***
********************************************************************************************************************************************

replace stakes = (total_fees_sq*pct_change_all) if pct_change_all >0
replace stakes = (-total_fees_sq*pct_change_all) if pct_change_all <0
replace positive_stakes = 0
replace negative_stakes = 0
replace positive_stakes = (total_fees_sq*pct_change_all / 1000000) if pct_change_all >0
replace negative_stakes = (-total_fees_sq*pct_change_all /1000000) if pct_change_all <0


*** original variables ***
local apolitical_indvars = "positive_stakes negative_stakes stake_dummy ln_total_allowed_sq hhi ln_medscape_salary_geo" 
local political_indvars = "positive_stakes negative_stakes stake_dummy ln_total_allowed_sq hhi ln_medscape_salary_geo donates_money_dem donates_money_rep donates_money_mod" 
local yeardummies = "y_1 y_2 y_3"

/*Multivariate logit models and Margin calculations */
/*Column (1) Specification*/
logit anycomment `apolitical_indvars' `yeardummies', robust cluster(provideryear) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)
**outreg2 using "Output/regression1_appendix_unlogged.tex", dec(3) alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label replace


/*Column (2) Specification: same with political controls*/
logit anycomment `political_indvars' `yeardummies', robust cluster(provideryear) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)

**outreg2 using "Output/regression1_appendix_unlogged.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`political_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append

/*Column (3) Specification -- controls for provider-year fixed effects*/
logit anycomment `apolitical_indvars' `yeardummies' year##groupid, robust cluster(provideryear) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)

**outreg2 using "Output/regression1_appendix_unlogged.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append

/*Column (4) Specification -- controls for provider-year fixed effects, political controls*/
logit anycomment `political_indvars' `yeardummies' year##groupid, robust cluster(provideryear) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)

**outreg2 using "Output/regression1_appendix_unlogged.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`political_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append

/*Column (5) Specification -- Conditional Fixed Effect Logit (Dem and GOP are time-invariant, so not estimated)*/
xtlogit anycomment `apolitical_indvars' `yeardummies', fe i(npi)
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)

**outreg2 using "Output/regression1_appendix_unlogged.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append


********************************************************************************************************************************************
***																																		 ***
***																																		 ***
*** Appendix Table A8: Estimating the Likelihood of Notice and Comment Participation: Logit and Conditional Fixed Effect Logit Estimates ***
***		With Percent Change (Re-estimation of Table A3 with unlogged percent change for the stakes variable)							 ***												 ***
***																																		 ***
***																																		 ***
********************************************************************************************************************************************


***  Use Output/regression1_appendix_pct_change.tex
replace stakes = (pct_change_all) if pct_change_all >0
replace stakes = (-pct_change_all) if pct_change_all <0
gen positive_stakes = 0
gen negative_stakes = 0
replace positive_stakes = (pct_change_all) if pct_change_all >0
replace negative_stakes = (-pct_change_all) if pct_change_all <0

gen stake_dummy = pct_change_all > 0

**** If changing between unlogged stakes and percent change, change the output files***

local apolitical_indvars = "positive_stakes negative_stakes stake_dummy ln_total_allowed_sq hhi ln_medscape_salary_geo" 
local political_indvars = "positive_stakes negative_stakes stake_dummy ln_total_allowed_sq hhi ln_medscape_salary_geo donates_money_dem donates_money_rep donates_money_mod" 
local yeardummies = "y_1 y_2 y_3"

/*Multivariate logit models and Margin calculations */
/*Column (1) Specification*/
logit anycomment `apolitical_indvars' `yeardummies', robust cluster(provideryear) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)
**outreg2 using "Output/regression1_appendix_pct_change.tex", dec(3) alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label replace


/*Column (2) Specification: same with political controls*/
logit anycomment `political_indvars' `yeardummies', robust cluster(provideryear) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)

**outreg2 using "Output/regression1_appendix_pct_change.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`political_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append

/*Column (3) Specification -- controls for provider-year fixed effects*/
logit anycomment `apolitical_indvars' `yeardummies' year##groupid, robust cluster(provideryear) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)

**outreg2 using "Output/regression1_appendix_pct_change.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append

/*Column (4) Specification -- controls for provider-year fixed effects, political controls*/
logit anycomment `political_indvars' `yeardummies' year##groupid, robust cluster(provideryear) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)

**outreg2 using "Output/regression1_appendix_pct_change.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`political_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append

/*Column (5) Specification -- Conditional Fixed Effect Logit (Dem and GOP are time-invariant, so not estimated)*/
xtlogit anycomment `apolitical_indvars' `yeardummies', fe i(npi)
matrix b = e(b)
matrix V = e(V)
lincom negative_stakes-positive_stakes
local coef1 = r(estimate)
local se1 = r(se)

**outreg2 using "Output/regression1_appendix_pct_change.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append


********************************************************************************************************************************************
***																																		 ***
***																																		 ***
*** Appendix Table A4: Rulemaking-related Antecedents of Campaign Expenditures: Regression Estimates 									 ***
***																																		 ***
***																																		 ***
********************************************************************************************************************************************

keep if year == 2012 | year == 2014
generate observed_spending = log_total_spending>0 & log_total_spending !=.
local apolitical_indvars = "positive_stakes negative_stakes stake_dummy ln_total_allowed_sq hhi ln_medscape_salary_geo" 
local political_indvars = "positive_stakes negative_stakes stake_dummy ln_total_allowed_sq hhi ln_medscape_salary_geo donates_money_dem donates_money_rep donates_money_mod" 
local yeardummies = "y_1 y_2 y_3"
reg log_total_spending `apolitical_indvars' `yeardummies', robust cluster(provideryear) vsquish
**outreg2 using "Output/regression2.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') label replace
reg log_total_spending `apolitical_indvars' `yeardummies' year##groupid, robust cluster(provideryear) vsquish
**outreg2 using "Output/regression2.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') label append
areg log_total_spending `apolitical_indvars' `yeardummies', absorb(npi) vsquish
**outreg2 using "Output/regression2.tex", dec(3) alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') label append

********************************************************************************************************************************************
***																																		 ***
***																																		 ***
*** Appendix Table A5: Rulemaking-related Antecedents of Campaign Expenditures: Regression Estimates, Fraction of contributions to GOP 	 ***
***																																		 ***
***																																		 ***
********************************************************************************************************************************************

local apolitical_indvars = "positive_stakes negative_stakes stake_dummy ln_total_allowed_sq hhi ln_medscape_salary_geo" 
local yeardummies = "y_1 y_2 y_3"

reg pgr `apolitical_indvars' `yeardummies' if observed_spending  > 0 , robust cluster(provideryear) vsquish
**outreg2 using "Output/regression2_repdv.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') label replace
reg pgr `apolitical_indvars' `yeardummies' year##groupid if observed_spending  > 0 , robust cluster(provideryear) vsquish
**outreg2 using "Output/regression2_repdv.tex", dec(3)  alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') label append
areg pgr `apolitical_indvars' `yeardummies' if observed_spending > 0 , absorb(npi) vsquish
**outreg2 using "Output/regression2_repdv.tex", dec(3) alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') label append



********************************************************************************************************************************************
***																																		 ***
***					      SPECIALTY ASSOCIATION PARTICIPATION	  																		 ***
*** 					Appendix Table A9: Stakes and Lobbying 																			 ***
***																																		 ***
********************************************************************************************************************************************


clear
set more off
use "Appendix.dta"
/******1. Show that autocorrelation in ln_total_allowed_sq is very high, which is why we
omit from the mfp regression******/
sort npi year
qui by npi: gen ln_total_allowed_sq_l1 = ln_total_allowed_sq[_n-1]
corr ln_total_allowed_sq ln_total_allowed_sq_l1

/******2. Code additional covariates ******/
gen ln_delta_all_neg = ln_delta_all*(ln_delta_all<0)
gen ln_delta_all_pos = ln_delta_all*(ln_delta_all>=0)
gen ln_delta_sign_dummy = ln_delta_all >=0
gen ln_medscape_salary_geo = ln(medscape_salary_geo)
gen ln_medscape_salary = ln(medscape_salary)
gen abs_ln_delta_all = abs(ln_delta_all)
egen provideryear = group(provider_type year)
gen stakes = 0
replace stakes = log10(total_fees_sq*pct_change_all) if pct_change_all >0
replace stakes = -log10(-total_fees_sq*pct_change_all) if pct_change_all <0
gen positive_stakes = 0
gen negative_stakes = 0
replace positive_stakes = log10(total_fees_sq*pct_change_all) if pct_change_all >0
replace negative_stakes = log10(-total_fees_sq*pct_change_all) if pct_change_all <0
gen stake_dummy = pct_change_all > 0
gen donates_money_democrat = pct_to_republican < 1/3 & pct_to_republican !=.
gen donates_money_republican = pct_to_republican >2/3 & pct_to_republican !=.
gen donates_money_moderate = (pct_to_republican !=.)*(1-donates_money_democrat)*(1-donates_money_republican)


joinby provider_type year using "Source/assn_lobbying.dta", unmatched(master)
replace comment_year = 0 if comment_year == .
gen numdocs=1

*** Collapse by provider type, year, and groupid
collapse (median) ln_total_allowed_sq hhi ln_medscape_salary_geo  ///
  medscape_salary medscape_salary_geo_adj (sum) total_fees_sq total_fees_alt numdocs stake_dummy, by(provider_type year groupid)

joinby provider_type year using "Source/complex_assns_no_dupes", unmatched(master)
replace comment_year = 0 if comment_year == .

replace log_amt = 0 if log_amt == . 
gen frac_winners = stake_dummy/numdocs
gen spec_stakes = 0
gen positive_spec_stakes = 0
gen negative_spec_stakes = 0
replace positive_spec_stakes = log10(total_fees_alt-total_fees_sq) if total_fees_alt-total_fees_sq >0
replace negative_spec_stakes = log10(total_fees_sq-total_fees_alt) if total_fees_alt-total_fees_sq <0
gen spec_stake_dummy = total_fees_alt-total_fees_sq > 0

*** Label the variables (repeated since these are locals not globals ****

label var comment_year "Spec. Soc. comment"
label var positive_spec_stakes "Gains (logged)"
label var negative_spec_stakes "Losses (logged)"
label var spec_stake_dummy "Any gain"
label var ln_total_allowed_sq "Allowed charges (logged)"
label var hhi "Procedure concentration"
label var ln_medscape_salary_geo "Salary (logged)"

**** Create the tables ****

local apolitical_indvars = "log_amt positive_spec_stakes negative_spec_stakes spec_stake_dummy ln_total_allowed_sq hhi" 
logit comment_year `apolitical_indvars' i.year i.groupid,  robust cluster(provider_type) vsquish


logit comment_year log_amt i.year i.groupid,  robust cluster(provider_type) vsquish
**outreg2 using "Output/specialty_lobbying_participation.tex", dec(3) keep(comment_year log_amt) alpha(0.001, 0.01, 0.05) nocons label replace

*ln_medscape_salary_geo"  not included because is constant for specialties

logit comment_year `apolitical_indvars' i.year i.groupid,  robust cluster(provider_type) vsquish
matrix b = e(b)
matrix V = e(V)
lincom negative_spec_stakes-positive_spec_stakes
local coef1 = r(estimate)
local se1 = r(se)
**outreg2 using "Output/specialty_lobbying_participation.tex", dec(3) alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') addstat("H0:Losses-Gains=0",`coef1',"se1",`se1') nocons label append


********************************************************************************************************************************************
***																																		 ***
***					      																												 ***
*** Table A11: Estimating the Likelihood of Individual and Specialty Society Participation in Notice and Comment Rulemaking 			 ***																							 ***
***																																		 ***
***																																		 ***
********************************************************************************************************************************************


clear
set more off
use "Working/working_data_medicare_commenting.dta"

/******1. Show that autocorrelation in ln_total_allowed_sq is very high, which is why we
omit from the mfp regression******/
sort npi year
qui by npi: gen ln_total_allowed_sq_l1 = ln_total_allowed_sq[_n-1]
corr ln_total_allowed_sq ln_total_allowed_sq_l1

/******2. Code additional covariates ******/
gen ln_delta_all_neg = ln_delta_all*(ln_delta_all<0)
gen ln_delta_all_pos = ln_delta_all*(ln_delta_all>=0)
gen ln_delta_sign_dummy = ln_delta_all >=0
gen ln_medscape_salary_geo = ln(medscape_salary_geo)
gen ln_medscape_salary = ln(medscape_salary)
gen abs_ln_delta_all = abs(ln_delta_all)
egen provideryear = group(provider_type year)
gen stakes = 0
replace stakes = log10(total_fees_sq*pct_change_all) if pct_change_all >0
replace stakes = -log10(-total_fees_sq*pct_change_all) if pct_change_all <0
gen positive_stakes = 0
gen negative_stakes = 0
replace positive_stakes = log10(total_fees_sq*pct_change_all) if pct_change_all >0
replace negative_stakes = log10(-total_fees_sq*pct_change_all) if pct_change_all <0
gen stake_dummy = pct_change_all > 0
gen donates_money_democrat = pct_to_republican < 1/3 & pct_to_republican !=.
gen donates_money_republican = pct_to_republican >2/3 & pct_to_republican !=.
gen donates_money_moderate = (pct_to_republican !=.)*(1-donates_money_democrat)*(1-donates_money_republican)

***** 3. Merge with association lobbying data ****
joinby provider_type year using "Source/assn_lobbying.dta", unmatched(master)
replace comment_year = 0 if comment_year == .

*encode provider_type, gen(provider_type_enc)

gen multi_comment = 1 if anycomment == 0
replace multi_comment = 2 if mass_comment == 1
replace multi_comment = 3 if non_mass_comment == 1

**** 4. Generate interactions *****
gen positive_stakes_speccom = positive_stakes*comment_year
gen negative_stakes_speccom = negative_stakes*comment_year
gen stake_dummy_speccom = stake_dummy*comment_year

local apolitical_indvars = "comment_year positive_stakes positive_stakes_speccom negative_stakes negative_stakes_speccom stake_dummy stake_dummy_speccom ln_total_allowed_sq hhi ln_medscape_salary_geo" 
local yeardummies = "y_1 y_2 y_3"

**** 5. Label variables so the **outreg2 output contains the names in the Appendix
label var comment_year "Spec. Soc. comment"
label var positive_stakes "Gains (logged)"
label var negative_stakes "Losses (logged)"
label var stake_dummy "Any gain"
label var ln_total_allowed_sq "Allowed charges (logged)"
label var hhi "Procedure concentration"
label var ln_medscape_salary_geo "Salary (logged)"
label var positive_stakes_speccom "Gains x Spec. Soc. cmt"
label var negative_stakes_speccom "Losses x Spec. Soc. cmt"
label var stake_dummy_speccom "Stake x Spec. Soc. cmt"

**** Write the actual table ******=

** Columns 1 and 2** 
logit anycomment `apolitical_indvars' `yeardummies', robust cluster(provideryear) vsquish
**outreg2 using "Output/mlogit_table.tex", dec(3) alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars') nocons label replace

logit anycomment `apolitical_indvars' `yeardummies' i.groupid, robust cluster(provideryear) vsquish
**outreg2 using "Output/mlogit_table.tex", dec(3) alpha(0.001, 0.01, 0.05) keep(`apolitical_indvars')  nocons label append

** Columns 3 and 4** (will be 3 4 and 5 in the output) 
mlogit multi_comment `apolitical_indvars' `yeardummies',  robust cluster(provider_type) vsquish
matrix b = e(b)
matrix V = e(V)
lincom [2]negative_stakes - [3]negative_stakes
local coef1 = r(estimate)
local se1 = r(se)

lincom [2]comment_year  - [3]comment_year
local coef2 = r(estimate)
local se2 = r(se)
**outreg2 using "Output/mlogit_table.tex", dec(3) keep(`apolitical_indvars') alpha(0.001, 0.01, 0.05) addstat("H_0: Neg. stakes equal",(`coef1'),"se1",(`se1'), "H_0: Spec. cmt. equal", `coef2',"se2",`se2') nocons label  append


** Columns 5 and 6 ** (will be 6 7 8 in the output)
mlogit multi_comment `apolitical_indvars' `yeardummies' i.groupid,  robust cluster(provider_type) vsquish
matrix b = e(b)
matrix V = e(V)
lincom [2]negative_stakes - [3]negative_stakes
local coef1 = r(estimate)
local se1 = r(se)

lincom [2]comment_year  - [3]comment_year
local coef2 = r(estimate)
local se2 = r(se)
**outreg2 using "Output/mlogit_table.tex", dec(3) keep(`apolitical_indvars') alpha(0.001, 0.01, 0.05) addstat("H_0: Neg. stakes equal",(`coef1'),"se1",(`se1'), "H_0: Spec. cmt. equal", `coef2',"se2",`se2')  nocons label append
